﻿
function SelectAll(parentControlId, selectorId, rowSelectorControlId)
{
    var grid = document.getElementById(parentControlId);  
    var inputFields;
    if(grid != null)
    {
        inputFields = grid.getElementsByTagName("input");
        for(var i=0;i<inputFields.length;i++)
        {
            if(inputFields[i].type == "checkbox")
            {
                //rowSelect is the id of the row selection checkbox
                var id = inputFields[i].id.toString();
                if(id.indexOf(rowSelectorControlId,0)>0)
                    inputFields[i].checked = document.getElementById(selectorId).checked;
            }
        }
    }
    else
    {
        inputFields = document.getElementsByTagName("input");
        for(var i=0;i<inputFields.length;i++)
        {
            if(inputFields[i].type == "checkbox")
            {
                //rowSelect is the id of the row selection checkbox
                var id = inputFields[i].id.toString();
                if(id.indexOf(parentControlId,0)>=0 && id.indexOf(rowSelectorControlId,0)>=0)
                    inputFields[i].checked = document.getElementById(selectorId).checked;
            }
        }
    }
}

function ascii_value (c)
{
	// restrict input to a single character
	c = c . charAt (0);

	// loop through all possible ASCII values
	var i;
	for (i = 0; i < 256; ++ i)
	{
		// convert i into a 2-digit hex string
		var h = i . toString (16);
		if (h . length == 1)
			h = "0" + h;

		// insert a % character into the string
		h = "%" + h;

		// determine the character represented by the escape code
		h = unescape (h);

		// if the characters match, we've found the ASCII value
		if (h == c)
			break;
	}
	return i;
}

function isLeapYear(year)
{
    if(isNaN(year))
        return false;
        
    var leapYear = false;
    leapYear = ( ( ( year % 4 ) == 0 ) && ( ( year % 100 ) != 0 ) || ( ( year % 400 ) == 0 ) );
    return leapYear;
}

function clearText(field, initialText, restoreColor)
{
    if(field!= null)
    {
        if(field.value == initialText)
        {
            field.value = "";
            field.style.color = restoreColor;
        }
    }
}

function resetText(field, initialText, initialColor)
{
    if(field.value == "")
    {
        field.value = initialText;
        field.style.color = initialColor;
    }
}

/***********************************************************
This method positions an element in the center of the screen
Requires : prototype.js
To Call the method
Event.observe(window, 'scroll', function(){
    positionCenter('testdiv');
});
***********************************************************/
//function positionCenter(elementName)
//{
//    $(elementName).absolutize();
//    var height = $(elementName).getHeight();
//    var width = $(elementName).getWidth();
//    var offSet = $(elementName).cumulativeOffset();
//    var scrollOffset = $(elementName).cumulativeScrollOffset();
//    
//    var x = (scrollOffset.left) + ( (document.viewport.getWidth() - width) / 2.0 );
//    var y = (scrollOffset.top) + ( (document.viewport.getHeight() - height) / 2.0 );
//    $(elementName).setStyle({top:y+"px",left:x+"px"});
//} 

function getWall(name,nummer,pPopup) 
{
    if (pPopup == '') pPopup = 'height=600,width=800';
    url = "viewwallpaper.aspx?id=" + nummer;
    ipwindow = open(name,"_blank","fullscreen=no,resizable=yes,scrollbars=yes,toolbar=no," + pPopup);
    ipwindow.location.href = url;
}

function SetErrorTheme(textboxName, isValid)
{
    var textbox = document.getElementById(textboxName);
    if(isValid == false)
        textbox.style.backgroundColor = '#FFEFEF';
    else
        textbox.style.backgroundColor = 'white';
}

